package com.ndp.fb.rdb.model;

import com.ndp.fb.rdb.annotation.Column;
import com.ndp.fb.rdb.annotation.Id;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Jacky on 2014/10/11.
 */
@Setter
@Getter
@NoArgsConstructor
public class User implements Serializable {
    private static final long serialVersionUID = 6713933397082540593L;
	/**
	 * as column id
	 */
    @Id
    private Long id;
	/**
	 * as column ticket
	 */
    private String ticket;
	/**
	 * as column username
	 */
    private String username;
	/**
	 * as column password
	 */
    private String password;
	/**
	 * as column email
	 */
    private String email;
	/**
	 * as column salt
	 */
    private String salt = "salt";
	/**
	 * as column locked
	 */
    private Boolean locked = Boolean.FALSE;
	/**
	 * as column status
	 */
    private Integer status = 0;
	/**
	 * as column nickname
	 */
    private String nickname;
    /**
     * as column company 已删除
     */
    //    private String company;
    /**
     * as column website 已删除
     */
    //    private String website;
	/**
	 * as column country
	 */
    private String country;
	/**
	 * as column timezone_id
	 */
    private String timezoneId;
	/**
	 * as column timezone_name
	 */
    private String timezoneName;
	/**
	 * as column update_time
	 */
    private Long updateTime;
	/**
	 * as column org_id
	 */
    private Long orgId;
	/**
	 * as column role_id
	 */
    private List<Long> roleId;
	/**
	 * as column invitation_code
	 */
    private String invitationCode;
	/**
	 * as column badgeNum
	 */
    @Column("badgeNum")
    private Long badgeNum = 0l;
	/**
	 * as column language
	 */
    private String language;
    private String phone;
    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }
    public User(Long userId,String username) {
    	this.id = userId;
        this.username = username;
    }

    public String getCredentialsSalt() {
        return username + salt;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        return id != null ? id.equals(user.id) : user.id == null;

    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", ticket='" + ticket + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", email='" + email + '\'' +
                ", salt='" + salt + '\'' +
                ", locked=" + locked +
                ", nickname=" + nickname +
//                ", company=" + company +
//                ", website=" + website +
                ", country=" + country +
                ", timezoneId=" + timezoneId +
                ", timezoneName=" + timezoneName +
                ", updateTime=" + updateTime +
                ", orgId=" + orgId +
                ",invitationCode=" + invitationCode +
                ",badgeNum=" + badgeNum +
                ",language=" + language +
                ",phone=" + phone +
                '}';
    }

}
